package mysql;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;

import org.firefly.db.dialect.IDialect;
import org.firefly.db.dialect.MySQLDialect;
import org.firefly.db.util.DBInfo;
import org.firefly.db.util.DBUtils;
import org.firefly.db.util.DBName;
import org.firefly.db.util.ArrayUtils;

public class InBy {
  /**
	 * @param args
	 * @throws Exception 
	 */
	public static void main1(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
		Class.forName("net.sourceforge.jtds.jdbc.Driver");
		Connection srcConn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.1.109:1433/eadpv4", "sa", "eplugger");
		Connection tarConn = java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/inby?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "inby", "123456");
		try {
			DBInfo srcInfo = new DBInfo(srcConn, null, DBName.SqlServer2005);
			DBInfo tarInfo = new DBInfo(tarConn, null, DBName.Mysql);
			DBUtils.dbConvertA2B(srcInfo, tarInfo,true);
		} finally{
			srcConn.close();
			tarConn.close();
		}
	}
	private static void main2(String[] aa) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		Connection srcConn = java.sql.DriverManager.getConnection("jdbc:mysql://112.126.71.107:3306/inby_tiku?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "inby_tiku", "inby0915");
		try {
			DBInfo srcInfo = new DBInfo(srcConn, null, DBName.Mysql);
			IDialect tarDia = new MySQLDialect();
			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/meta.sql");
			OutputStreamWriter osw = new OutputStreamWriter(fos);
			DBUtils.expertInsertSQL(srcInfo, tarDia, osw, new String[]{"BIZ_USER_INFO","SYS_USER","BIZ_FEED","BIZ_FEED_COMMENT","BIZ_FORHELP","BIZ_FORHELP_COMMENT","SYS_UPLOAD_FILE"}, null, true);
		} finally{
			srcConn.close();
		}
	}
	/**
	 * 生成外键的索引
	 */
	public static void main3(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		Connection srcConn = java.sql.DriverManager.getConnection("jdbc:mysql://112.126.71.107:3306/inby_tiku?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "inby_tiku", "inby0915");
		try {
			DBInfo srcInfo = new DBInfo(srcConn, null, DBName.Mysql);
			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/fkIndexs.sql");
			OutputStreamWriter osw = new OutputStreamWriter(fos);
			DBUtils.expertFKIndexSQL(srcInfo, osw, null, true);
		} finally{
			srcConn.close();
		}
	}
	/**
	 * 2个数据库的结构对比
	 */
	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		Connection srcConn = java.sql.DriverManager.getConnection("jdbc:mysql://182.92.67.193:3306/inby?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "inby", "inbyTest2014");
		Connection tarConn = java.sql.DriverManager.getConnection("jdbc:mysql://112.126.71.107:3306/inby_tiku?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "inby_tiku", "inby0915");
		try {
			DBInfo srcInfo = new DBInfo(srcConn, null, DBName.Mysql);
			DBInfo tarInfo = new DBInfo(tarConn, null, DBName.Mysql);
			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/cp.sql");
			OutputStreamWriter osw = new OutputStreamWriter(fos);
			DBUtils.compareDB(srcInfo, tarInfo, osw,true);//(srcConn, srcDia, osw, null, true);
		} finally{
			srcConn.close();
		}
	}

}
